package com.neusoft.service.impl;

import java.security.NoSuchAlgorithmException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.neusoft.mapper.DeliveryManMapper;
import com.neusoft.mapper.OrdersMapper;
import com.neusoft.po.DeliveryMan;
import com.neusoft.po.Orders;
import com.neusoft.service.DeliveryManService;
import com.neusoft.util.MD5Lock;

@Service
public class DeliveryManServiceImpl implements DeliveryManService {

	@Autowired
	private DeliveryManMapper deliveryManMapper;
	@Autowired
	private OrdersMapper ordersMapper;

	@Override
	public List<Orders> listOrdersById(String deliveryManId) {
		// TODO Auto-generated method stub
		return ordersMapper.listOrdersByDeliveryManId(deliveryManId);
	}
	
	@Override
	public List<Orders> listUndeliveryOrders() {
		// TODO Auto-generated method stub
		return ordersMapper.listUndeliveryOrders();
	}

	@Override
	@Transactional
	public DeliveryMan getDeliveryManByIdByPass(DeliveryMan deliveryMan) {
		// TODO Auto-generated method stub
		try {
			deliveryMan.setPassword(MD5Lock.getMD5Str(deliveryMan.getPassword()));
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		DeliveryMan temp = deliveryManMapper.getDeliveryManByIdByPass(deliveryMan);
		if (temp == null) {
			return null;
		}
		return temp;
	}

	@Override
	@Transactional
	public int saveDeliveryMan(DeliveryMan deliveryMan) {
		// TODO Auto-generated method stub
		try {
			deliveryMan.setPassword(MD5Lock.getMD5Str(deliveryMan.getPassword()));
		} catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return deliveryManMapper.saveDeliveryMan(deliveryMan);
	}

	@Override
	public DeliveryMan getDeliveryManById(String deliveryManId) {
		// TODO Auto-generated method stub
		return deliveryManMapper.getDeliveryManById(deliveryManId);
	}

	@Override
	public int deliveryOrder(Integer orderId, String deliveryManId) {
		// TODO Auto-generated method stub
		return ordersMapper.deliveryOrder(orderId, deliveryManId);
	}

	

}
